package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import com.atguigu.springcloud.service.PaymentFeignService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @auther zzyy
 * @create 2020-02-20 0:05
 */
@Api(value = "OrderFeignController") //swagger2
@RestController
@Slf4j
public class OrderFeignController {
    @Resource
    private PaymentFeignService paymentFeignService;

    //GET Restful 一个参数
    @ApiOperation("根据id")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "path", dataType = "Long")
    })
    @GetMapping(value = "/consumer/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id) {
        return paymentFeignService.getPaymentById(id);
    }


    //GET 两个 Restful 参数
    @ApiOperation("根据id和name查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "path", dataType = "Long"),
            @ApiImplicitParam(name = "name", value = "name", required = true, paramType = "path", dataType = "String")
    })
    @GetMapping(value = "/consumer/payment/get/{id}/{name}")
    public CommonResult<Payment> getPaymentByIdAndName(@PathVariable("id") Long id, @PathVariable("name") String name) {
        return paymentFeignService.getPaymentByIdAndName(id, name);
    }


    //GET 一个 k=v 参数
    @ApiOperation("根据id")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "long")
    })
    @GetMapping(value = "/consumer/payment/get01")
    public CommonResult<Payment> getPaymentById01(@RequestParam("id") Long id) {
        return paymentFeignService.getPaymentById01(id);
    }


    //GET 两个 k=v 参数
    @ApiOperation("根据id和name查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "name", value = "name", required = true, paramType = "query", dataType = "string")
    })
    @GetMapping(value = "/consumer/payment/get02")
    public CommonResult<Payment> getPaymentById02(@RequestParam("id") Long id,
                                                  @RequestParam("name") String name) {
        return paymentFeignService.getPaymentById02(id, name);
    }



    //GET 一个k=v参数 + 一个Restful参数
    @ApiOperation("根据id和name查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "path", dataType = "long"),
            @ApiImplicitParam(name = "name", value = "name", required = true, paramType = "query", dataType = "string")
    })
    @GetMapping(value = "/consumer/payment/get03/{id}")
    public CommonResult<Payment> getPaymentById03(@PathVariable("id") Long id,
                                                  @RequestParam("name") String name) {
        return paymentFeignService.getPaymentById03(id,name);
    }

    //POST 一个对象
    @ApiOperation("新增payment")
    @PostMapping("/payment/create")
    public CommonResult create(@RequestBody Payment payment) {
        return paymentFeignService.create(payment);

    }

    //POST 一个对象 + 一个Restful参数
    @ApiOperation("新增payment")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "path", dataType = "long")
    })
    @PostMapping("/payment/create01/{id}")
    public CommonResult create01(@RequestBody Payment payment,@PathVariable("id")Long id) {
        return paymentFeignService.create01(payment,id);

    }

    //POST 一个对象 + 一个Restful参数 + 一个k=v参数
    @ApiOperation("新增payment")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "path", dataType = "long"),
            @ApiImplicitParam(name = "name", value = "name", required = true, paramType = "query", dataType = "string")
    })
    @PostMapping("/payment/create02/{id}")
    public CommonResult create02(@RequestBody Payment payment,@PathVariable("id")Long id,@RequestParam("name")String name) {
        return paymentFeignService.create02(payment,id,name);

    }





    @GetMapping(value = "/consumer/payment/feign/timeout")
    public String paymentFeignTimeout() {
        // OpenFeign客户端一般默认等待1秒钟
        return paymentFeignService.paymentFeignTimeout();
    }
}
